﻿using System.Web.UI.Design;


namespace Folks.UI.Design
{
	internal static class DesignerHelper
	{
		private static string openTable = "<table style=\"border:0px;font:messagebox;font-size:12px;padding:3px;{0}\" cellspacing=\"0\" cellpadding=\"0\">";
		private static string closeTable = "</table>";
		private static string openRow = "<tr style=\"{0}\">";
		private static string closeRow = "</tr>";
		private static string openCol = "<td style=\"{0}\" {1}>";
		private static string closeCol = "</td>";

		internal static string GetHtmlWithDescription(string title, string description, bool error)
		{
			string html = string.Format(openTable, (error) ? "color:red;" : string.Empty);
			html += GetSimpleRow(title, "font-weight:bold;", string.Empty);
			html += GetSimpleRow(description, string.Empty, string.Empty);
			return html + closeTable;
		}

		internal static string GetHtmlWithRegions(string title, string description, int quantity)
		{
			string html = string.Format(openTable, "border:solid 1px #ccc;");
			string header = "<strong>" + title + "</strong> - " + description;
			html += GetSimpleRow(header, "background-color:#eaeaea;border-bottom:solid 1px #ccc;", string.Empty);
			for(int i = 0;i<quantity;i++)
				html += GetSimpleRow(string.Empty, string.Empty, DesignerRegion.DesignerRegionAttributeName + "=" + i);
			return html + closeTable;
		}

		internal static string GetSimpleRow(string value, string style, string parameter)
		{
			string row = string.Format(openRow, string.Empty);
			row += string.Format(openCol, string.IsNullOrEmpty(style) ? string.Empty : style, parameter);
			row += value;
			row += closeCol;
			return row + closeRow;
		}
	}
}
